Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
point /username to /[user]/[tab].js and not [user]/index.js in nextjs

I'm attempting to create a user profile page that generates content based on the current tab the user is in.

The tab is decided based on what is passed in the URL (e.g. /username/tab1). The only issue with this is that one of the valid tabs the user can visit actually has a blank value (/username, to get the default tab).

However, when you enter this into the browser, Next automatically assumes I want to retrieve /[user]/index.js (which doesn't exist), when in actuality what I want to get is /[user]/[tab].js and pass a blank value to the tab property in context.query.

Is this possible without creating a separate index.js and [tab].js file?

// Exported inside /pages/[user]/[tab].js
export const getServerSideProps = async (context) => {
    const { page, tab } = context.query;

    // When we're on /username/foo it should output "foo".
    // When we're on /username it should output "".
    console.log(tab); 
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can achieve this using an optional catch-all route.

So, rename your [tab].js as [[...tab]].js, so it will catch also the requests to /username without a tab. Then in your code you'll handle tab as optional.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda